import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { StatueUserPlayer } from "../../../scene/player/entity/StatueUserPlayer";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { ESex } from "../../../../../Message/Public/ESex";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { LoveTaskInviteInfo } from "../../../model/loveTask/LoveTaskInviteInfo";
import { ActionType } from "../../../scene/modle/data/ActionType";
import { DirectionType } from "../../../scene/modle/data/DirectionType";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { SPublicMiniPlayer } from "../../../../../Message/Public/SPublicMiniPlayer";
//class LoveTaskPlayerPanel
    
    export  class LoveTaskPlayerPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._talkPlayer = new PlayerMiniInfo();
            this._bodyPlayr = new StatueUserPlayer();
            this._bodyPlayr.x = 75;
            this._bodyPlayr.y = 212;
            this._inviteBtn = ObjCreate.createGLoadedButton(ResFileConst.PartnerLove, 0, 0, 57, 53);
            this._inviteBtn.x = 0;
            this._inviteBtn.y = 110;
            this._inviteBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onInviteBtnClickHandler);
            this._talkBtn = ObjCreate.createGLoadedButton(ResFileConst.TalkLove, 0, 0, 50, 46);
            this._talkBtn.x = this._inviteBtn.x + 5;
            this._talkBtn.y = this._inviteBtn.y + 45;
            this._talkBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onTalkBtnClickHandler);
            this._iconBmp = new Object /* flash.display.Bitmap */();
            this._iconBmp.y = 220;
            return;
        }

        /* internal  */onInviteBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._miniPlayer) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.LoveTaskInviteReq, this._miniPlayer));
            }
            return;
        }

        /* internal  */onTalkBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._miniPlayer) 
            {
                this._talkPlayer.miniPlayer = this._miniPlayer;
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivate, this._talkPlayer));
            }
            return;
        }

        /* internal  */onLoveResLoadedHandler(): void
        {
            if (this._invitePlayer) 
            {
                if (this._invitePlayer.isFriend) 
                {
                    if (Cache.instance.role.entityInfo.sex != ESex._ESexMan) 
                    {
                        this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.loveFriend2);
                    }
                    else 
                    {
                        this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.loveFriend1);
                    }
                    this._iconBmp.y = 220;
                }
                else if (this._invitePlayer.isCity) 
                {
                    if (Cache.instance.role.entityInfo.sex != ESex._ESexMan) 
                    {
                        this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.loveCity2);
                    }
                    else 
                    {
                        this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.loveCity1);
                    }
                }
                else 
                {
                    if (Cache.instance.role.entityInfo.sex != ESex._ESexMan) 
                    {
                        this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.lovePlayer2);
                    }
                    else 
                    {
                        this._iconBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.lovePlayer1);
                    }
                    this._iconBmp.y = 212;
                }
                this._iconBmp.x = (this.width - this._iconBmp.width) / 2 + 10;
                addChild(this._iconBmp);
            }
            return;
        }

        public updateData(arg1: LoveTaskInviteInfo): void
        {
            if (!arg1) 
            {
                return;
            }
            this._invitePlayer = arg1;
            if (!this._invitePlayer.miniPlayer) 
            {
                return;
            }
            this._miniPlayer = arg1.miniPlayer;
            this._bodyPlayr.career = this._miniPlayer.career;
            this._bodyPlayr.sex = this._miniPlayer.sex;
            this._bodyPlayr.camp = this._miniPlayer.camp;
            this._bodyPlayr.updateName(Cache.instance.loveTask.getUserHtmlName(this._miniPlayer, true));
            this._bodyPlayr.actionState = ActionType.Stand;
            this._bodyPlayr.direction = DirectionType.South;
            this._bodyPlayr.updateClothes(this._miniPlayer.mapId);
            this._bodyPlayr.updateWeapons(this._miniPlayer.copyId);
            this._bodyPlayr.isClear(false);
            this._bodyPlayr.play();
            addChildAt(this._bodyPlayr, 0);
            LoaderHelp.addResCallBack(ResFileConst.loveTask, this.onLoveResLoadedHandler);
            addChild(this._inviteBtn);
            addChild(this._talkBtn);
            return;
        }

        public dispose(): void
        {
            if (this._iconBmp.parent) 
            {
                removeChild(this._iconBmp);
            }
            if (this._inviteBtn.parent) 
            {
                removeChild(this._inviteBtn);
            }
            if (this._talkBtn.parent) 
            {
                removeChild(this._talkBtn);
            }
            this._invitePlayer = null;
            this._miniPlayer = null;
            this._bodyPlayr.dispose();
            return;
        }

        public /* override */ get width(): number
        {
            return 138;
        }

        /* internal */ /* var */_bodyPlayr: StatueUserPlayer;

        /* internal */ /* var */_inviteBtn: GLoadedButton;

        /* internal */ /* var */_talkBtn: GLoadedButton;

        /* internal */ /* var */_iconBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_miniPlayer: SPublicMiniPlayer;

        /* internal */ /* var */_invitePlayer: LoveTaskInviteInfo;

        /* internal */ /* var */_talkPlayer: PlayerMiniInfo;
    }
